// Copyright (c) 2025 Huawei Technologies Co., Ltd.
// openUBMC is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//         http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Description: 封装和解析KVM消息报文

#ifndef KVM_MESSAGE_HPP
#define KVM_MESSAGE_HPP

#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <stdexcept>

class KVMMessage {
private:
    uint32_t length_{0};                 ///< 消息体长度，4字节（big-endian）
    uint16_t cmdType_{0};                ///< 消息类型，2字节（big-endian）
    uint8_t bladeId_{0};                 ///< 单板槽位号，1字节
    uint8_t reserved_{0};                ///< 预留块，1字节
    std::vector<uint8_t> body_;          ///< 消息体

public:
    KVMMessage();
    ~KVMMessage();

    std::vector<uint8_t> Pack(uint16_t kvmCmdType, int bladeId, const std::vector<uint8_t>& data);
    bool Unpack(const std::string& data);

    uint16_t GetCmdType() const;
    uint8_t GetBladeId() const;
    std::vector<uint8_t> GetBody() const;
};

#endif // KVM_MESSAGE_HPP